﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using WCFMINERP.Contracts.InterFaces;
using WCFMINERP.COM;

namespace WCFMINERP.Update
{
    public partial class FrmChangePwd : Form
    {
        public FrmChangePwd()
        {
            InitializeComponent();
        }
        ChannelFactory<IShop> _proxyShop;//创建代理
        IShop ishop;
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtPwd.Text != txtPwdToo.Text)
            {
                MessageBox.Show("两次输入密码不一致请确认");
                return;
            }
            try
            {
                _proxyShop = new ChannelFactory<IShop>("IShop");
                ishop = _proxyShop.CreateChannel();
                int intVal = ishop.ChangeUserPwd(txtUsername.Text.Trim(), Md5HashCode.GetHash(textEditoLDPWD.Text), Properties.Settings.Default.SHACODE, Md5HashCode.GetHash(txtPwd.Text));
                if (intVal == -4)
                {
                    MessageBox.Show("您输入旧密码不正确，如果您忘记密码请联系" + Properties.Settings.Default.ServerName);

                }
                else if (intVal == -3)
                {
                    MessageBox.Show("您输入登录名不正确，如果您忘记密码请联系" + Properties.Settings.Default.ServerName);

                }
                else if (intVal == -2)
                {
                    MessageBox.Show("您的认证码已失效，请联系 " + Properties.Settings.Default.ServerName);

                }
                else if (intVal == -1)
                {
                    MessageBox.Show("服务可能已经关闭，请联系 " + Properties.Settings.Default.ServerName);

                }
                else
                {
                    MessageBox.Show("您的密码已经重置，请牢记您的新密码");
                    this.Close();
                }
            }
            catch
            {
                MessageBox.Show("服务出错，请联系 " + Properties.Settings.Default.ServerName);
 
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        
    }
}
